<?php	
	include "curl.php";
	switch ($_SERVER['HTTP_ORIGIN']) {
		default:
		header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
		header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
		header('Access-Control-Max-Age: 1000');
		header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
		break;
	}
	if(isset($_POST['user_id'])){
		$name = $_POST['user_id'];
		$password = $_POST['password'];			
		
		$token = getToken($name,$password);
		
		if ($token=="failed")
		{
			$err = array('message' => "error");

			echo json_encode($err);
		}
		else
		{
			$tenants = getTenants($token);
			echo json_encode(array('token'=>$token,'tenants'=>$tenants));	
		}
	}
	if(isset($_POST['tenants_Name'])){		
		$token = $_POST['token'];
		$tenants = getTenants($token);		
		$tenantToken = getTenantstoken($_POST['tenants_Name'],$_POST['token']);
		//print_r($tenants);
		$compute_limits = getCompute_limits($_POST['tenants_Id'],$tenantToken);
		$blockstorage_limits = getBlockstorage_limits($_POST['tenants_Id'],$tenantToken);
		
		echo json_encode(array('compute_limits'=>$compute_limits,'blockstorage_limits'=>$blockstorage_limits));
	}	
		
?>
